package com.gh.ggkt.vod.controller;


import com.atguigu.ggkt.model.vod.Course;
import com.atguigu.ggkt.vo.vod.CourseFormVo;
import com.atguigu.ggkt.vo.vod.CoursePublishVo;
import com.atguigu.ggkt.vo.vod.CourseQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gh.Result;
import com.gh.ggkt.vod.service.CourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author Eric Fang
 * @since 2022-09-11
 */
@RestController
@RequestMapping("/admin/vod/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 点播课程列表
     */
    @ApiOperation("点播课程列表")
    @PostMapping("/{page}/{limit}")
    public Result findPageCourse(@PathVariable Long page,
                                 @PathVariable Long limit,
                                 @RequestBody CourseQueryVo courseQueryVo) {
        Page<Course> pageParam = new Page<>(page, limit);
        Map<String, Object> map = courseService.findPageCourse(pageParam, courseQueryVo);
        return Result.ok(map);
    }

    /**
     * 添加课程基本信息
     */
    @ApiOperation("添加课程基本信息")
    @PostMapping("save")
    public Result saveCourseInfo(@RequestBody CourseFormVo courseFormVo){
        Long courseId = courseService.saveCourseInfo(courseFormVo);
        return Result.ok(courseId);
    }

    /**
     * 根据id查询课程信息
     */
    @GetMapping("get/{id}")
    @ApiOperation("据id查询课程信息")
    public Result getCourseInfoById(@PathVariable Long id){
        CourseFormVo courseFormVo = courseService.getCourseInfoById(id);
        return Result.ok(courseFormVo);
    }

    /**
     * 修改课程信息
     */
    @PostMapping("update")
    @ApiOperation("修改课程信息")
    public Result updateCourseInfo(@RequestBody CourseFormVo courseFormVo){
        courseService.updateCourseInfo(courseFormVo);
        return Result.ok(courseFormVo.getId());
    }

    /**
     * 根据课程id查询课程发布信息
     */
    @ApiOperation("根据课程id查询课程发布信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable Long id){
        CoursePublishVo coursePublishVo = courseService.getCoursePublishVo(id);
        return Result.ok(coursePublishVo);
    }

    /**
     * 课程最终发布
     */
    @ApiOperation("课程最终发布")
    @GetMapping("publishCourse/{id}")
    public Result publishCourse(@PathVariable Long id){
        courseService.publishCourse(id);
        return Result.ok(null);
    }

    /**
     * 删除课程
     */
    @DeleteMapping("removeCourse/{id}")
    @ApiOperation("删除课程")
    public Result removeCourse(@PathVariable Long id){
        courseService.removeCourse(id);
        return Result.ok(null);
    }

}

